import { NodeStatus } from "../../../common/Enum";
import { GEnemyHP } from "../../../common/Global";
import { toFixed } from "../../../common/Util";
import BTCondition from "../../Base/BTCondition";
import Boss1Tree from "../Tree/Boss1Tree";

/** 生命百分比条件 */
export default class ConditionalPercentageHP extends BTCondition {

    constructor(
        private tree: Boss1Tree,
        /** 最大生命比例 */
        private maxRate: number = 1,
        /** 最小生命比例 */
        private minRate: number = 0,
    ) {
        super()
    }
    onUpdate(): NodeStatus {
        if (
            this.maxRate >= toFixed(this.tree.enemy.hp / GEnemyHP[this.tree.enemy.type]) &&
            toFixed(this.tree.enemy.hp / GEnemyHP[this.tree.enemy.type]) > this.minRate
        ) {
            return NodeStatus.Success
        }
        return NodeStatus.Failure
    }
}